var vue = new Vue({
    el: "#main",
    data() {
        return {
            change: {
                oldPassword: '',
                password: '',
                repeatPassword: '',
            },
            loading: false
        }
    },
    mounted() {
        // console.log(getToken)
    },
    methods: {
        // 确认修改密码
        confirm() {
            this.loading = true
            if (this.change.oldPassword == "") {
                if (document.getElementsByClassName('el-message').length === 0) {
                    this.$message({
                        message: '请输入当前密码',
                        type: 'error',
                        duration: 3000
                    });
                }
                this.loading = false
            } else if (this.change.password.length < 8) {
                if (document.getElementsByClassName('el-message').length === 0) {
                    this.$message({
                        message: '密码格式错误',
                        type: 'error',
                        duration: 3000
                    });
                }
                this.loading = false
            } else if (this.change.repeatPassword != this.change.password) {
                if (document.getElementsByClassName('el-message').length === 0) {
                    this.$message({
                        message: '请确认密码一致',
                        type: 'error',
                        duration: 3000
                    });
                }
                this.loading = false
            } else {
                ajax({
                    url: formal + "/person/modify-pwd",
                    type: 'POST',
                    data: this.change,
                    success: (res) => {
                        if (res.status == 1) {
                            localStorage.clear()
                            window.location.href = 'login.html'
                            this.loading = false
                        }
                        if (document.getElementsByClassName('el-message').length === 0) {
                            this.$message({
                                message: res.message,
                                type: 'success',
                                duration: 3000
                            });
                        }
                    }
                })
            }
        },
    }
})